import Data.List
import Data.Array

primes = 2 : filter ( (==1) . length . primeFactors ) [3,5..]

primeFactors :: Integer -> [Integer]
primeFactors n = factor n primes
	where
	factor n (p:ps)
		| p*p > n		 = [n]
		| n `mod` p == 0 = p : factor ( n `div` p )	(p:ps)
		| otherwise		 = factor n ps

factors :: Integer -> [Integer]
factors 1 = [1]
factors n
	| length (t) == 1 = [1,n]
	| otherwise = nub $ map product $ subsequences t
	where t = primeFactors n
	
properFactors :: Integer -> [Integer]
properFactors n = (factors n)\\[n]

factorSum :: Integer -> Integer
factorSum n = (sum.factors) n

isAbundant :: Integer -> Bool
isAbundant n = ((factorSum n) - n) > n

abundantIntegers :: [Integer]
abundantIntegers = filter isAbundant [1..28123]

notSumOfTwoAbundants = filter (\x->(not (any isAbundant (rests x)))) [1..28124] 
	where
		rests x = map (x-) $ takeWhile (<= x `div` 2) abundantIntegers
		
euler_023 = sum notSumOfTwoAbundants